﻿@using Jhong.FunMVC.Razor;
@{
    var model = @ViewData["model"] as Jhong.FunMVCBlog.Admin.Model.BlogArticleViewModel;
}
<style>
    .jh1 {
        width: 100%;
        border-style: solid;
        border-width: 1px;
        border-color: #ccc;
        margin: 10px 0 0 0;
        padding: 7px 7px 7px 7px;
        color: blue;
        display: none;
    }

    .jh2 {
    }
</style>
<!-- DataTables CSS -->
<link href="/Asset/UE/themes/default/css/umeditor.min.css" rel="stylesheet" />
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">编辑博客</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <h5 style="color:red;" id="opMsg"></h5>
        <form action="/Post/EditPost" method="post">
            <div class="form-group">
                <label for="Title">标题</label>
                <input type="text" class="form-control" id="Title" name="Title" value="@model.Title" placeholder="请输入标题">
            </div>
            <div class="form-group">
                <label for="Content">正文</label>
                <script id="Content" name="Content" type="text/plain" style="width:100%;height:500px;">
                    @RazorHTMLHelper.Raw(model.Content)
                </script>
            </div>
            <div class="form-group">
                <label for="Summary">摘要 <font style="color:#a39999;font-size:x-small;font-weight:100;">&nbsp;[选填，不填写则自动截取正文内容]</font> </label>
                <script id="Summary" name="Summary" type="text/plain" style="width:100%;height:100px;">
                    @RazorHTMLHelper.Raw(model.Summary)
                </script>
            </div>
            <div class="form-group">
                <label for="TagName">标签<font id="showjh1" style="color:blue;font-size:x-small;font-weight:100;cursor:pointer;">&nbsp;[点我查看已有标签]</font> </label>
                <input type="text" class="form-control" id="TagName" name="TagName" value="@model.TagName" placeholder="选填，多个标签用','隔开">
                <div class="jh1" status="hide"></div>
            </div>
            <div class="form-group">
                <label for="CategoryID">分类</label>
                @RazorHTMLHelper.HTML.DropDownList("CategoryID", @ViewData["categoryies"] as IList<SelectListItem>, new { @class = "form-control" })
            </div>
            <div class="form-group">
                <label for="CategoryID">其他选项</label>
                <br />
                <label class="checkbox-inline">
                    <input type="checkbox" id="IsPublish" name="IsPublish" value="true" @if (model.IsPublish) { <text> checked="checked" </text>    }> 发布
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="IsTop" name="IsTop" value="true" @if (model.IsTop) { <text> checked="checked" </text>     }> 置顶
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="UpdatePublishTime" name="UpdatePublishTime" value="true"> 强制刷新发布时间
                </label>
            </div>
            <input type="hidden" name="ID" id="ID" value="@model.ID" />
            <input type="hidden" name="CreateTime" id="CreateTime" value="@model.CreateTime" />
            <input type="hidden" name="PublishTime" id="PublishTime" value="@model.PublishTime" />
            <button id="sub" class="btn btn-primary btn-sm">提交</button>
        </form>
    </div>
    <!-- /.col-lg-12 -->
</div>
<script>
</script>
<script src="/Asset/UE/umeditor.config.js"></script>
<script src="/Asset/UE/umeditor.min.js"></script>
<script src="/Asset/UE/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    (function ($, um) {

        var tags = '@ViewData["tags"]'.split(',');
        var tagarr = [];
        for (var t in tags) {
            tagarr.push("<a href='###' class='jh2' >" + tags[t] + "</a>");
        }
        var jh1 = $(".jh1");
        jh1.html(tagarr.join('&nbsp;&nbsp;'));
        var tagName = $("#TagName");
        $(".jh2").on("click", function () {
            var txt = $(this).text();
            var tmpTagName = tagName.val().split(",");
            for (var i in tmpTagName) if (tmpTagName[i] == txt) return false;
            if (tagName.val().length > 0) tagName.val(tagName.val() + "," + txt);
            else tagName.val(txt);
        });
        $("#showjh1").click(function () {
            var status = jh1.attr("status");
            if (status == "hide") {
                jh1.attr("status", "show");
                jh1.show();
            } else {
                jh1.attr("status", "hide");
                jh1.hide();
            } return false;
        });

        var uec = um.getEditor('Content');
        var ues = um.getEditor('Summary');

        $("#sub").click(function () {
            var form = $("form");
            var summary = $("#Summary");
            var summaryText = um.getEditor("Summary").getContentTxt();
            if (/^\s*$/.test(summaryText)) {
                $("#HasSummary").val("false");
                var contentText = um.getEditor("Content").getContentTxt();
                um.getEditor("Summary").setContent(contentText.substr(0, 100), false)
            }
            var data = form.serialize();
            $.post(form.attr("action"), data, function (res) {
                if (res.IsSuccess) {
                    $("#tmpData").val(res.Msg);
                    $("#ii2").trigger("click");
                } else {
                    alert(res.Msg);
                    return false;
                }
            });

            return false;
        });

    }(jQuery, UM));
</script>